package im.elephas.androfan.common.widget;

import im.elephas.androfan.activity.AndroFanActivity;
import im.elephas.androfan.activity.BacktrackActivity;
import im.elephas.androfan.activity.PersonalInfoActivity;
import im.elephas.androfan.activity.SendMessageActivity;
import im.elephas.androfan.fanfouapi.items.StatusItem;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.ViewGroup;

public class ReplyStatusWidget extends StatusWidget {

	@Override
	protected void showDialog() {
		Builder dialog = new AlertDialog.Builder(mActivity);
		String[] sel = { "回复", "转发", "私信", "收藏", "查看资料", "回复跟踪" };
		dialog.setTitle("对@" + statusItem.getUser().getScreenName());
		dialog.setItems(sel, new Dialog.OnClickListener() {

			@Override
			public void onClick(DialogInterface dialog, int which) {
				Intent i;
				Bundle b;
				switch (which) {
				case 0:
					i = new Intent(getActivity(), SendMessageActivity.class);
					b = new Bundle();
					b.putBoolean("isreply", true);
					b.putString("atname", statusItem.getUser().getName());
					b.putString("replyid", statusItem.getUser().getId());
					i.putExtras(b);
					getActivity().startActivityForResult(i, 0);
					break;
				case 1:
					getApiCaller().refanfouStatus(statusItem);
					break;
				case 2:
					break;
				case 3:
					getApiCaller().createFavoriteStatus(statusItem);
					break;
				case 4:
					i = new Intent(getActivity(), PersonalInfoActivity.class);
					b = new Bundle();
					b.putSerializable("item", statusItem.getUser());
					i.putExtras(b);
					getActivity().startActivityForResult(i, 0);
					break;
				case 5:
					i = new Intent(getActivity(), BacktrackActivity.class);
					b = new Bundle();
					b.putString("id", statusItem.getId());
					i.putExtras(b);
					getActivity().startActivityForResult(i, 0);
					break;
				default:
					break;
				}
			}
		});
		dialog.show();
	}

	public ReplyStatusWidget(ViewGroup parentView, AndroFanActivity mActivity) {
		super(parentView, mActivity);
		getWidgetView().setBackgroundColor(Color.argb(100, 250, 250, 250));
	}

	public ReplyStatusWidget(ViewGroup parentView, AndroFanActivity mActivity,
			StatusItem si) {
		this(parentView, mActivity);
		setStatusItem(si);
		if (si.getInReplyToUserId().equals(mActivity.getFanfouApi().getUser().getId()))
			getWidgetView().setBackgroundColor(Color.argb(100, 204, 105, 15));
	}
}
